< previous page page_375 next page >

Page 375
#define constantname value_expression
The value_expression term can be an expression made up of one or more other constants (including previously defined constants). Standard arithmetic operations can be used, as can the | operator (bitwise OR) and & operator (bitwise AND). You may also see the >> and << operators (shift right and shift left, which shift the individual bits in the expression by the number of positions specified by the operator).
Hex values in C/C++ are prefixed with the sequence 0x or 0X instead of &H. Constants may have an L suffix, indicating that they are a Long value. Expressions are not limited to numeric valuesthey may consist of strings or generic text as well. The entire value_expression term is substituted in place of the constantname term when the program is compiled, so any text that would be allowed in that position is allowed.
Declarations are converted into the following generic Visual Basic form:
Public Const constantname = constant_value
You can use the same constant name, but you must calculate out the value of the constant based on the header file. Here's an example from the cpuid.h file:
#define VERSION 0x0101 // Must be 2 bytes in length.
Public Const VERSION = &H0101  ' Must be 2 bytes in length.
Here's a hint: You can typically do a global search and replace the term "#define" with "Public Const" to make the porting effort easier. In most cases, all that will remain is to add the equal signs that are needed byVisual Basic. One of the nice things about this part of the porting process is that the Visual Basic compiler will catch most of your errors (such as forgetting the equal sign or forgetting to change the 0x hex indicator to &H).
Step 5:
Comment Out the typedef Declarations
The C typedef command is used to describe one type of variable in terms of another type. Its generic form is:
typedef variable_type new_type
where variable_type is a currently defined C/C++ data type and new_type is a new name for that type. Consider this example from speed.h:
typedef unsigned short ushort;

 
< previous page page_375 next page >